;(function webpackUniversalModuleDefinition(root, factory) {
  if (typeof exports === 'object' && typeof module === 'object')
    module.exports = factory()
  else if (typeof define === 'function' && define.amd) define([], factory)
  else {
    var a = factory()
    for (var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i]
  }
})(window, function() {
  return /******/ (function(modules) {
    // webpackBootstrap
    /******/ // The module cache
    /******/ var installedModules = {} // The require function
    /******/
    /******/ /******/ function __webpack_require__(moduleId) {
      /******/
      /******/ // Check if module is in cache
      /******/ if (installedModules[moduleId]) {
        /******/ return installedModules[moduleId].exports
        /******/
      } // Create a new module (and put it into the cache)
      /******/ /******/ var module = (installedModules[moduleId] = {
        /******/ i: moduleId,
        /******/ l: false,
        /******/ exports: {}
        /******/
      }) // Execute the module function
      /******/
      /******/ /******/ modules[moduleId].call(
        module.exports,
        module,
        module.exports,
        __webpack_require__
      ) // Flag the module as loaded
      /******/
      /******/ /******/ module.l = true // Return the exports of the module
      /******/
      /******/ /******/ return module.exports
      /******/
    } // expose the modules object (__webpack_modules__)
    /******/
    /******/
    /******/ /******/ __webpack_require__.m = modules // expose the module cache
    /******/
    /******/ /******/ __webpack_require__.c = installedModules // define getter function for harmony exports
    /******/
    /******/ /******/ __webpack_require__.d = function(exports, name, getter) {
      /******/ if (!__webpack_require__.o(exports, name)) {
        /******/ Object.defineProperty(exports, name, {
          enumerable: true,
          get: getter
        })
        /******/
      }
      /******/
    } // define __esModule on exports
    /******/
    /******/ /******/ __webpack_require__.r = function(exports) {
      /******/ if (typeof Symbol !== 'undefined' && Symbol.toStringTag) {
        /******/ Object.defineProperty(exports, Symbol.toStringTag, {
          value: 'Module'
        })
        /******/
      }
      /******/ Object.defineProperty(exports, '__esModule', { value: true })
      /******/
    } // create a fake namespace object // mode & 1: value is a module id, require it // mode & 2: merge all properties of value into the ns // mode & 4: return value when already ns object // mode & 8|1: behave like require
    /******/
    /******/ /******/ /******/ /******/ /******/ /******/ __webpack_require__.t = function(
      value,
      mode
    ) {
      /******/ if (mode & 1) value = __webpack_require__(value)
      /******/ if (mode & 8) return value
      /******/ if (
        mode & 4 &&
        typeof value === 'object' &&
        value &&
        value.__esModule
      )
        return value
      /******/ var ns = Object.create(null)
      /******/ __webpack_require__.r(ns)
      /******/ Object.defineProperty(ns, 'default', {
        enumerable: true,
        value: value
      })
      /******/ if (mode & 2 && typeof value !== 'string')
        for (var key in value)
          __webpack_require__.d(
            ns,
            key,
            function(key) {
              return value[key]
            }.bind(null, key)
          )
      /******/ return ns
      /******/
    } // getDefaultExport function for compatibility with non-harmony modules
    /******/
    /******/ /******/ __webpack_require__.n = function(module) {
      /******/ var getter =
        module && module.__esModule
          ? /******/ function getDefault() {
              return module['default']
            }
          : /******/ function getModuleExports() {
              return module
            }
      /******/ __webpack_require__.d(getter, 'a', getter)
      /******/ return getter
      /******/
    } // Object.prototype.hasOwnProperty.call
    /******/
    /******/ /******/ __webpack_require__.o = function(object, property) {
      return Object.prototype.hasOwnProperty.call(object, property)
    } // __webpack_public_path__
    /******/
    /******/ /******/ __webpack_require__.p = '' // Load entry module and return exports
    /******/
    /******/
    /******/ /******/ return __webpack_require__((__webpack_require__.s = 0))
    /******/
  })(
    /************************************************************************/
    /******/ [
      /* 0 */
      /***/ function(module, __webpack_exports__, __webpack_require__) {
        'use strict'
        __webpack_require__.r(__webpack_exports__)
        /* harmony export (binding) */ __webpack_require__.d(
          __webpack_exports__,
          'PolyvUpload',
          function() {
            return PolyvUpload
          }
        )
        function _typeof(obj) {
          if (
            typeof Symbol === 'function' &&
            typeof Symbol.iterator === 'symbol'
          ) {
            _typeof = function _typeof(obj) {
              return typeof obj
            }
          } else {
            _typeof = function _typeof(obj) {
              return obj &&
                typeof Symbol === 'function' &&
                obj.constructor === Symbol &&
                obj !== Symbol.prototype
                ? 'symbol'
                : typeof obj
            }
          }
          return _typeof(obj)
        }
        function _classCallCheck(instance, Constructor) {
          if (!(instance instanceof Constructor)) {
            throw new TypeError('Cannot call a class as a function')
          }
        }
        function _defineProperties(target, props) {
          for (var i = 0; i < props.length; i++) {
            var descriptor = props[i]
            descriptor.enumerable = descriptor.enumerable || false
            descriptor.configurable = true
            if ('value' in descriptor) descriptor.writable = true
            Object.defineProperty(target, descriptor.key, descriptor)
          }
        }

        function _createClass(Constructor, protoProps, staticProps) {
          if (protoProps) _defineProperties(Constructor.prototype, protoProps)
          if (staticProps) _defineProperties(Constructor, staticProps)
          return Constructor
        }

        /**
         * 用于向用户提供接口
         * @param {object} options 用户可以自行设置的参数
         */
        var PolyvUpload =
          /* #__PURE__ */
          (function() {
            function PolyvUpload(options) {
              _classCallCheck(this, PolyvUpload)

              var LOCATION = window.location
              var PROTOCOL = window.location.protocol

              if (
                ((!options.userid ||
                  !options.ts ||
                  !options.hash ||
                  !options.sign) &&
                  !options.requestUrl) ||
                !options.uploadButtton
              ) {
                throw new TypeError('缺少必选的上传参数！')
              }

              if (options.width && typeof options.width !== 'number') {
                delete options.width
                console.log('上传参数width必须为数字类型')
              }

              if (options.height && typeof options.height !== 'number') {
                delete options.width
                console.log('上传参数height必须为数字类型')
              }

              if (options.fileLimit && typeof options.fileLimit !== 'number') {
                delete options.fileLimit
                console.log('上传参数fileLimit必须为数字类型')
              }

              if (
                options.fileNumberLimit &&
                typeof options.fileNumberLimit !== 'number'
              ) {
                delete options.fileNumberLimit
                console.log('上传参数fileNumberLimit必须为数字类型')
              } // var urlPrefix = PROTOCOL + '//playertest.polyv.net/player2/huiying/plug-in-v2'; // 测试地址

              var urlPrefix = PROTOCOL + '//static.polyv.net/file/plug-in-v2' // CDN地址
              // var urlPrefix = PROTOCOL + '//localhost:8088/plug-in-v2'; // 本地测试

              this.options = {
                userid: options.userid,
                ts: options.ts,
                // 13位的毫秒级时间戳
                ptime: options.ts,
                // 13位的毫秒级时间戳
                hash: options.hash,
                // 是根据将ts和writeToken按照顺序拼凑起来的字符串进行MD5计算得到的值
                sign: options.sign,
                // 是根据将secretkey和ts按照顺序拼凑起来的字符串进行MD5计算得到的值
                component: options.component || 'all',
                // 可以设置为videoList（只显示视频列表）、 uploadList（只显示上传列表）、all（默认值，显示上传列表和视频列表）
                cataid: options.cataid || 1,
                // 上传目录id，默认值为1
                luping: (options.luping || 0) + '',
                // 开启视频课件优化处理，对于上传录屏类视频清晰度有所优化。可设置为0或1，默认值为0，表示不开启课件优化
                defaultTagPlaceholder:
                  options.defaultTagPlaceholder || '标签 用" , "分隔',
                // 自定义标签输入框占位符
                defaultDescPlaceholder:
                  options.defaultDescPlaceholder || '添加描述',
                // 自定义视频描述输入框占位符
                extra: JSON.stringify(options.extra || {}),
                // 可添加的属性为keepsource：源文件播放（不对源文件进行编码）。可设置为0（对源文件进行编码）或1（源文件播放）
                fileLimit: options.fileLimit,
                // 可上传单个视频的大小，默认不限制
                fileLimitTips:
                  options.fileLimitTips || '该视频文件过大，请重新选择',
                // 超出大小限制时的提示语
                fileNumberLimit: options.fileNumberLimit,
                fileNumberLimitTips:
                  options.fileNumberLimitTips ||
                  '\u6BCF\u6B21\u4E0A\u4F20\u7684\u6587\u4EF6\u4E2A\u6570\u4E0D\u80FD\u8D85\u8FC7'.concat(
                    options.fileNumberLimit,
                    '\u4E2A'
                  ),
                response: options.response || function() {},
                // function，返回指定视频的信息时的回调函数
                openWrap: options.openWrap || function() {},
                //
                uploadSuccess: options.uploadSuccess || function() {},
                // function，当前文件上传完毕时触发的回调函数
                uploadFail: options.uploadFail || function() {},
                // function，当前文件上传失败时触发的回调函数
                url: LOCATION.href,
                urlPrefix: urlPrefix,
                source: 'polyv-upload'
              }
              this.uploadButton = document.getElementById(options.uploadButtton)
              this.width = options.width
                ? options.width < 900
                  ? 900
                  : options.width
                : 1000 // 弹框的宽，最小900px；默认值1000px

              this.height = options.height
                ? options.height < 500
                  ? 500
                  : options.height
                : 600 // 弹框的高，最小500px；默认值600px

              this.requestUrl = options.requestUrl
              this.retryTimes = 5 // 默认使用HTML5方式上传
              // this.url = urlPrefix + '/upload-html5/build/index.html';

              this.url = urlPrefix + '/build/index.html' // 测试flash版
              // this.url = urlPrefix + '/upload-flash/index.html';

              this._init()
            }

            _createClass(PolyvUpload, [
              {
                key: '_addHander',
                value: function _addHander(ele, type, handler) {
                  if (ele.addEventListener) {
                    ele.addEventListener(type, handler, false)
                  } else if (ele.attachEvent) {
                    ele.attachEvent('on' + type, handler)
                  } else {
                    ele['on' + type] = handler
                  }
                }
              },
              {
                key: '_checkH5Support',
                value: function _checkH5Support() {
                  var input = document.createElement('input')
                  var fileSupport = !!(window.File && window.FileList)
                  var xhr = new XMLHttpRequest()
                  var fd = !!window.FormData
                  return (
                    'multiple' in input &&
                    fileSupport &&
                    'onprogress' in xhr &&
                    'upload' in xhr &&
                    fd
                  )
                }
              },
              {
                key: '_init',
                value: function _init() {
                  var _this = this

                  if (!this._checkH5Support()) {
                    // 不支持HTML5新特性时使用flash上传；需要带网络协议
                    this.url =
                      this.options.urlPrefix + '/upload-flash/index.html'
                  }

                  this._addHander(this.uploadButton, 'click', function() {
                    _this.openWrap()
                  })

                  this._addHander(
                    window,
                    'message',
                    this._receiveMsg.bind(this)
                  )

                  var i = 0

                  if (this.requestUrl) {
                    this._getSign({
                      success: function success(res) {
                        _this._initIframe(function() {
                          _this.update(res)

                          console.log('(插件内部)第' + i++ + '次刷新...')
                        })
                      }
                    })

                    setInterval(function() {
                      _this._getSign({
                        success: function success(res) {
                          _this.update(res)

                          console.log('(插件内部)第' + i++ + '次刷新...')
                        }
                      })
                    }, 3 * 50 * 1000)
                  } else {
                    this._initIframe()
                  }
                }
              },
              {
                key: '_getSign',
                value: function _getSign(_ref) {
                  var success = _ref.success,
                    fail = _ref.fail
                  var self = this
                  var xhr = new XMLHttpRequest()
                  xhr.open(
                    'GET',
                    this.requestUrl + '?id=' + encodeURI(new Date().getTime())
                  ) // 防止IE9浏览器发起GET请求时总是返回304的问题

                  xhr.onreadystatechange = function() {
                    if (xhr.readyState === 4) {
                      if (xhr.status === 200 && typeof success === 'function') {
                        try {
                          success(JSON.parse(xhr.responseText))
                          self.retryTimes = 5
                        } catch (err) {
                          if (self.retryTimes <= 0) {
                            if (typeof fail === 'function') {
                              fail({})
                            }

                            return
                          }

                          self.retryTimes--

                          self._getSign({
                            success: success,
                            fail: fail
                          })
                        }
                      } else if (typeof fail === 'function') {
                        fail(JSON.parse(xhr.responseText))
                      }
                    }
                  }

                  xhr.send(null)
                }
              },
              {
                key: '_initIframe',
                value: function _initIframe(callbackFun) {
                  var iframe = this._createIframe()

                  this.frameMsg = iframe.contentWindow

                  if (typeof callbackFun === 'function') {
                    callbackFun()
                  }

                  function loadIframe(iframe) {
                    if (iframe.readyState && iframe.readyState !== 'complete') {
                    } else {
                      this.update()
                    }
                  }

                  if (iframe.attachEvent) {
                    iframe.attachEvent('onload', loadIframe.bind(this, iframe))
                  } else {
                    iframe.onload = loadIframe.bind(this, iframe)
                  }
                }
              },
              {
                key: '_createIframe',
                value: function _createIframe() {
                  var wrapAll = document.createElement('div'),
                    wrap = document.createElement('div'),
                    frameWrap = document.createElement('div'),
                    cancle = document.createElement('span'),
                    iframe = document.createElement('iframe')
                  wrapAll.setAttribute('id', 'polyv-wrapAll')
                  wrapAll.style.display = 'none'
                  wrap.style.cssText =
                    'display: block;position: fixed;left: 0;top: 0;width: 100%;height: 100%;z-index: 1001;background-color: #000;-moz-opacity: 0.5;opacity: .50;filter: alpha(opacity=50);'
                  frameWrap.style.cssText = 'display: block;position: fixed;left: 0;top: 0;bottom: 0;right: 0;width: '
                    .concat(this.width, 'px;height: ')
                    .concat(
                      this.height,
                      'px;margin: auto;z-index: 1002;box-shadow: 0 0 25px rgba(0,0,0,0.7);border-radius: 10px;'
                    )
                  cancle.innerHTML = '&times;'
                  cancle.style.cssText =
                    'width: 26px;height: 26px;position: absolute;top: 0px;right: 0px;cursor: pointer;background: #eee;text-align: center;line-height: 26px;color: #666;font-size: 16px;font-family: microsoft yahei;border-radius: 0 10px 0 0;'

                  cancle.onclick = function() {
                    wrapAll.style.display = 'none'
                  }

                  iframe.setAttribute('src', this.url)
                  iframe.setAttribute('id', 'polyv-iframe')
                  iframe.setAttribute('width', this.width)
                  iframe.setAttribute('height', this.height)
                  iframe.style.cssText =
                    'width: 100%;height: 100%;z-index: 1002;border:none;border-radius: 10px;background-color: #fff;'
                  frameWrap.appendChild(iframe)
                  frameWrap.appendChild(cancle)
                  wrapAll.appendChild(wrap)
                  wrapAll.appendChild(frameWrap)
                  // document.getElementsByTagName('body')[0].appendChild(wrapAll)
                  document
                    .getElementsByClassName('el-dialog__wrapper')[0]
                    .appendChild(wrapAll)
                  return iframe
                }
              },
              {
                key: '_receiveMsg',
                value: function _receiveMsg(event) {
                  try {
                    var msgData = JSON.parse(event.data)
                  } catch (err) {
                    return
                  }

                  switch (msgData.type) {
                    case 'VIDEO_INFO':
                      if (typeof this.options.response === 'function') {
                        this.options.response(msgData.data)
                      }

                      break

                    case 'FILE_COMPLETE':
                      if (
                        this.options &&
                        typeof this.options.uploadSuccess === 'function'
                      ) {
                        this.options.uploadSuccess(msgData.data)
                      }

                      break

                    case 'FILE_FAIL':
                      if (typeof this.options.uploadFail === 'function') {
                        this.options.uploadFail(msgData.data)
                      }

                      break

                    default:
                      break
                  }
                } // 用于更新上传参数
              },
              {
                key: 'update',
                value: function update() {
                  if (_typeof(arguments[0]) === 'object') {
                    for (var i in arguments[0]) {
                      if (arguments[0].hasOwnProperty(i)) {
                        this.options[i] = arguments[0][i]
                      }
                    }

                    if (arguments[0].ts) {
                      this.options.ptime = arguments[0].ts
                    }
                  }

                  this.frameMsg.postMessage(
                    JSON.stringify(this.options),
                    this.url
                  )
                } // 关闭插件
              },
              {
                key: 'openWrap',
                value: function openWrap() {
                  this.frameMsg.postMessage(
                    JSON.stringify({
                      openWrap: true
                    }),
                    this.url
                  )
                  this.options.openWrap && this.options.openWrap()
                  document.getElementById('polyv-wrapAll').style.display =
                    'block'
                } // 打开插件
              },
              {
                key: 'closeWrap',
                value: function closeWrap() {
                  document.getElementById('polyv-wrapAll').style.display =
                    'none'
                }
              }
            ])

            return PolyvUpload
          })()

        /***/
      }
      /******/
    ]
  )
})
